<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <base href="<%=basePath%>">
  <title>校园宿舍管理系统</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link href="Style/Style.css" rel="stylesheet" type="text/css" />
</head>
<script language="JavaScript" type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js">

  function mycheck(){
    if(isNull(form1.Type.value)){
      alert("请选择身份！");
      return false;
    }
    if(isNull(form1.Username.value)){
      alert("请输入用户名！");
      return false;
    }
    if(isNull(form1.Password.value)){
      alert("请输入密码！");
      return false;
    }
    if(isNull(form1.code.value)){
      alert("请输入验证码");
    }
  }

  function isNull(str){
    if ( str == "" ) return true;
    var regu = "^[ ]+$";
    var re = new RegExp(regu);
    return re.test(str);
  }

  $(function() {

  });

  function changeImg() {
    var imgSrc = $("#imgObj");
    var src = imgSrc.attr("src");
    imgSrc.attr("src", chgUrl(src));
  }

  // 时间戳
  // 为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳
  function chgUrl(url) {
    var timestamp = (new Date()).valueOf();
    url = url.substring(0, 20);
    if ((url.indexOf("&") >= 0)) {
      url = url + "×tamp=" + timestamp;
    } else {
      url = url + "?timestamp=" + timestamp;
    }
    return url;
  }


</script>
<body>
<center>
  <br><br><br><br><br>
  <table width="684" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="292" align="center" valign="top" background="Images/Login.jpg">
        <table width="400" height="201" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td height="52" align="center"><h3>校园宿舍管理系统</h3></td>
          </tr>
          <tr>
            <td align="center" valign="top">
              <form name="form1" action="GoLogin.action" method="post" onSubmit="return mycheck()">
                <table width="90%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="25" colspan="2" align="center" class="STYLE2"><span style="color:red;">
                    <%if(request.getAttribute("Msg")!=null){%>
                    <%=request.getAttribute("Msg")%>
                    <%}%>
                  </span></td>
                  </tr>
                  <tr>
                    <td height="0" align="right" class="STYLE2">身份：</td>
                    <td align="left"><select name="Type" id="Type">
                      <option value="">请选择</option>
                      <option value="系统管理员">系统管理员</option>
                      <option value="楼宇管理员">楼宇管理员</option>
                      <option value="学生">学生</option>
                    </select></td>
                  </tr>
                  <tr>
                    <td width="37%" height="30" align="right" class="STYLE2">用户名：</td>
                    <td width="300" align="left"><input type="text" name="Username" id="Username" class="text1" /></td>
                  </tr>
                  <tr>
                    <td height="30" align="right" class="STYLE2">密码：</td>
                    <td align="left"><input type="password" name="Password" id="Password" class="text1" /></td>
                  </tr>
                  <tr>
                    <td width="37%" height="30" align="right" class="STYLE2">验证码：</td>
                    <td align="left">
                      <input type="text" name="code" id="code" class="text1" />
                      <img id="imgObj" alt="验证码" src="${pageContext.request.contextPath}/getCode">
                      &nbsp;&nbsp;<a href="#" onclick="javascript:history.back(0)">换一张</a>
                    </td>
                  </tr>

                  <tr>
                    <td height="30" colspan="2" align="center"><label>
                      <input type="submit" name="button" id="button" value="登录">
                    </label></td>
                  </tr>

                </table>
              </form>

            </td>
          </tr>
        </table></td>
    </tr>
  </table>


</center>
</body>
</html>
